package com.ruoyi.portal.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.portal.domain.Recruitment;
import com.ruoyi.portal.service.IRecruitmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 招聘Controller
 *
 * @author cjie
 * @date 2021-06-13
 */
@Api(tags = " 招聘")
@RestController
@RequestMapping("/recruitment")
public class RecruitmentController extends BaseController {
    @Autowired
    private IRecruitmentService recruitmentService;

    /**
     * 查询招聘列表
     */
    @ApiOperation(value="查询招聘列表", notes="查询招聘列表")
    @GetMapping("/list")
    public TableDataInfo list(Recruitment recruitment) {
        startPage();
        List<Recruitment> list = recruitmentService.selectRecruitmentList(recruitment);
        return getDataTable(list);
    }

    /**
     * 导出招聘列表
     */
    @ApiOperation(value="导出招聘列表", notes="导出招聘列表")
    @PreAuthorize(hasPermi = "portal:recruitment:export")
    @Log(title = "招聘", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Recruitment recruitment) throws IOException {
        List<Recruitment> list = recruitmentService.selectRecruitmentList(recruitment);
        ExcelUtil<Recruitment> util = new ExcelUtil<Recruitment>(Recruitment.class);
        util.exportExcel(response, list, "招聘数据");
    }
    /**
     * 获取招聘详细信息
     */
    @ApiOperation(value="获取招聘详细信息", notes="获取招聘详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(recruitmentService.selectRecruitmentById(id));
    }

    /**
     * 新增招聘
     */
    @ApiOperation(value="新增招聘", notes="新增招聘")
    @PreAuthorize(hasPermi = "portal:recruitment:add")
    @Log(title = "招聘", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Recruitment recruitment) {
        return toAjax(recruitmentService.insertRecruitment(recruitment));
    }

    /**
     * 修改招聘
     */
    @ApiOperation(value="修改招聘", notes="修改招聘")
    @PreAuthorize(hasPermi = "portal:recruitment:edit")
    @Log(title = "招聘", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Recruitment recruitment) {
        return toAjax(recruitmentService.updateRecruitment(recruitment));
    }

    /**
     * 删除招聘
     */
    @ApiOperation(value="删除招聘", notes="删除招聘")
    @ApiImplicitParam(name = "ids", value = "招聘ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "portal:recruitment:remove")
    @Log(title = "招聘", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(recruitmentService.deleteRecruitmentByIds(ids));
    }
}
